* Need to consider variance by party on economic and moral issues
* to create std of party on issues, need egen. by party
* only 3 parties are at least 20 members


/* by partido, sort: egen pty_std_ESMOSEXOUNIONCIVIL=sd(VAL2MESMOSEXOUNIONCIVIL)
by partido, sort: egen pty_std_aborto=sd(VAL6borto)

* Neoliberalism (STATE IN TEH ECONOMY)
by partido, sort: egen pty_std_roleofstateinecon=sd(EM1)

*state in public services
by partido, sort: egen pty_std_rosinpubservices=sd(p29)


* to cull moral and economic questions for our own merge

*Brazil 2007-10 (study 75)

*/ 

*use "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/_annual survey versions/2010/BASEDATOS_BRASIL_75 2010.DTA"

keep Per_leg Partido N_Estudo SOCD4 EM1 ROES1_a ROES1_b ROES1_c ROES1_d ROES1_e /// 
ROES1_f ROES1_g PRIV1 PRIV2 GP1_1 GP1_2 VAL1 VAL2 RE1 RE1a RE1a_out RE1b  IMP1a ///
ID1 ID2 SOCD5 SOCD7 IMP1a

gen wave=2
*this not in original

save  "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/Pitt projects/_PELA 2022/consolidated surveys/Brazil2007to2010" , replace


gen country="Brazil"

label variable IMP1a "IMP1a impostos diretos/indiretos "
label variable Partido "partido"
label variable SOCD4 "SOCD4 sexo"
label variable EM1 "EM1 regulacion de la economia" 
label variable ROES1_a "ROES1_a state ownership of business"
label variable ROES1_b "ROES1_b state as responsible for well being"
label variable ROES1_c "ROES1_c state as responsible job creation"
label variable ROES1_d "ROES1_d state as responsible inequality"
label variable ROES1_e "ROES1_e state as responsible for pensions"
label variable ROES1_f "ROES1_f state as responsible for health care"
label variable ROES1_g "state as responsible for university education" 
label variable PRIV1 "PRIV1 State control of public services"
label variable PRIV2 "PRIV2 state control of natural resources"
label variable GP1_1 "GP1_1 spend more on what?"
label variable GP1_2 "GP1_2 spend more on what else?"
label variable VAL1 "VAL1 Same sex marriage"
label variable VAL2 "VAL2 abortion"

label variable RE1  "RE1  ¿Es adepto de alguna religión?"
label variable RE1a "RE1a   ¿Cuál es su religión?"
label variable RE1a_out "RE1a_out   ¿Cuál es su religión?"
label variable RE1b "RE1b religion frequency"

gen female=0
replace female=1 if SOCD4==2


rename N_Estudo nestu
gen date=2007
rename IMP1a eco_tax
rename Partido partido
rename SOCD4 sex
rename EM1 eco_regulated
rename ROES1_a eco_education_p
rename ROES1_b eco_wellbeing
rename ROES1_c eco_employment
rename ROES1_d eco_inequality
rename ROES1_e eco_pensions
rename ROES1_f eco_health
rename ROES1_g eco_education_u


rename  PRIV1 eco_services
rename  PRIV2 eco_natural
rename  GP1_1 state_spend
rename  GP1_2 state_spend2
rename  VAL1 val_ssm
rename  VAL2 val_abortion

rename SOCD7 education
rename SOCD5 age

gen regular_church=0
replace regular_church=1 if RE1b==4 | RE1b==5
replace regular_church=.5 if RE1b==3 

*not in original; Brazil uses different religion question; (adepto rather than creyente)
rename RE1 religious
replace religious=. if religious>2



gen     church_attend = 1 if RE1b==1 
replace church_attend = 3 if RE1b==2
replace church_attend = 5 if RE1b==3
replace church_attend = 8 if RE1b==4
replace church_attend = 10 if RE1b==5
replace church_attend = . if RE1b>5
 
* old had rename RE1b church_attend, but given 1-5 scale, need to redo



gen rel_catholic=0
replace rel_catholic=1 if RE1a==1

gen rel_evangelical=0
replace rel_evangelical=1 if RE1a==4
* Valentina adds "if religious==1"


gen rel_other=.



 
*val_abortion is 1-10 wiuth 1=against; in 2003 survey it was reversed  


lab define val_abortion ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion val_abortion













gen partylab=""
replace partylab="BR PRB" if partido==10
replace partylab="BR PP" if partido==11
replace partylab="BR PDT" if partido==12
replace partylab="BR PT" if partido==13
replace partylab="BR PTB" if partido==14
replace partylab="BR PMDB" if partido==15
replace partylab="BR PSC" if partido==20
replace partylab="BR PR" if partido==22
replace partylab="BR PPS" if partido==23
replace partylab="BR DEM" if partido==25
replace partylab="BR PSB" if partido==40
replace partylab="BR PV" if partido==43
replace partylab="BR PSDB" if partido==45
replace partylab="BR PCdoB" if partido==65
replace partylab="BR Others" if partido==75

gen party=partylab
drop partido
gen partido=partylab

save "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/Pitt projects/_PELA 2022/consolidated surveys/Brazil2007to2010", replace


* append using "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/Pitt projects/_PELA 2022/consolidated surveys/Brazil2003to2007.dta", force
